library(tidyverse)
library(readxl)
path = "files/Challenge1025.xlsx"
input = read_excel(path, range = "B3:D11")
test = read_excel(path, range = "F3:G9")
step = 5
min = floor(min(input$Qty) / step) * step
max = ceiling(max(input$Qty)/ step) * step
breaks = seq(min, max, by = step)
labels <- c(
paste0(breaks[1], "-", breaks[2]),
map2_chr(breaks[-length(breaks)], breaks[-1], ~ paste0(.x + 1, "-", .y))
) %>%
.[-1]
result = input %>%
mutate(Qty = cut(Qty, breaks = breaks, labels = labels)) %>%
summarise(Amount = sum(Amount), .by = Qty)
r2 = tibble(`Qty Group` = labels) %>%
left_join(result, by = c("Qty Group" = "Qty")) %>%
replace_na(list(Amount = 0))
all.equal(r2, test, check.attributes = FALSE)
#> [1] TRUECrispo - Excel Challenge 10 2025
excel-challenges
weekly-exercises
Easy Sunday Excel Challenge

Challenge Description
Easy Sunday Excel Challenge
⭐ Qty Group ⭐Create Qty Group and Sum the Amount
Solutions
Logic:
Reads the workbook range needed for the challenge
Aggregates or ranks values at the correct grouping level
Builds the intermediate helper columns that drive the final answer
Strengths:
- The R solution stays compact and mirrors the workbook logic closely.
Areas for Improvement:
- The code assumes the workbook layout and named ranges remain stable.
Gem:
- The best part of the solution is choosing a tidy intermediate shape before producing the final answer.
import pandas as pd
import numpy as np
path = "files/Challenge1025.xlsx"
input = pd.read_excel(path, usecols="B:D", skiprows=2, nrows=9)
test = pd.read_excel(path, usecols="F:G", skiprows=2, nrows=6).rename(columns=lambda x: x.replace('.1', ''))
step = 5
min_qty = np.floor(input["Qty"].min() / step) * step
max_qty = np.ceil(input["Qty"].max() / step) * step
breaks = np.arange(min_qty, max_qty + step, step)
labels = [f"{int(breaks[i-1] + 1)}-{int(breaks[i])}" for i in range(1, len(breaks))]
input["Qty_group"] = pd.cut(input["Qty"], bins=breaks, labels=labels, right=True, include_lowest=True)
result = input.groupby("Qty_group", observed=True)["Amount"].sum().reset_index()
result.rename(columns={"Qty_group": "Qty Group"}, inplace=True)
all_groups = pd.DataFrame({"Qty Group": labels})
r2 = pd.merge(all_groups, result, on="Qty Group", how="left")
r2["Amount"] = r2["Amount"].fillna(0)
r2["Amount"] = r2["Amount"].astype("int64")
print(test.equals(r2)) # TrueLogic:
Reads the workbook range needed for the challenge
Aggregates or ranks values at the correct grouping level
Applies the rule iteratively until the output is complete
Strengths:
- The Python version keeps the same rule in a direct pandas-oriented workflow.
Areas for Improvement:
- As with the R version, any workbook layout change would require small adjustments.
Gem:
- The implementation stays close to the stated challenge instead of adding unnecessary complexity.
Difficulty Level
This task is easy to moderate:
- The business rule is readable, but the workbook still needs a few careful transformation steps.